package monitor

import (
	"expvar"
	"runtime"
	"time"
)

var (
	_start_time = time.Now()
)

func init() {
	expvar.Publish("maxprocs", expvar.Func(getGoMaxProcs))
	expvar.Publish("uptime", expvar.Func(calcUptime))
	expvar.Publish("version", expvar.Func(getGoVersion))
	expvar.Publish("os", expvar.Func(getGoOS))
	expvar.Publish("cpu", expvar.Func(getNumCPU))
	expvar.Publish("goroutine", expvar.Func(getNumGoroutine))
	expvar.Publish("cgocall", expvar.Func(getNumCgoCall))
}

func getGoMaxProcs() interface{} {
	return runtime.GOMAXPROCS(0)
}

func getGoVersion() interface{} {
	return runtime.Version()
}

func calcUptime() interface{} {
	return time.Since(_start_time).String()
}

func getGoOS() interface{} {
	return runtime.GOOS
}

func getNumCPU() interface{} {
	return runtime.NumCPU()
}

func getNumGoroutine() interface{} {
	return runtime.NumGoroutine()
}

func getNumCgoCall() interface{} {
	return runtime.NumCgoCall()
}
